package code.example.zookeeper.master;

/**
 * Created by yanlei on 2017/6/9.
 */
public class ZookpeerConfig {
    //zookpeeper 服务地址字串，格式：ip:port;ip:port;ip:port;
    private String connectString;
    //两次重试之间的停顿时间
    private int sleepTimeMsBetweenRetries=1000;
    //最大重试次数
    private int maxRetries=5;

    // 会话超时时间，单位为毫秒，默认60000ms
    private int sessionTimeoutMs=60000;
    // 连接创建超时时间，单位为毫秒，默认是15000ms
    private int connectTimeoutMs=15000;

    //zookpeeper path前缀 如myApp,则创建test节点，则全称为：/myApp/test
    private String namespace="zk";

    public String getConnectString() {
        return connectString;
    }

    public void setConnectString(String connectString) {
        this.connectString = connectString;
    }

    public int getSleepTimeMsBetweenRetries() {
        return sleepTimeMsBetweenRetries;
    }

    public void setSleepTimeMsBetweenRetries(int sleepTimeMsBetweenRetries) {
        this.sleepTimeMsBetweenRetries = sleepTimeMsBetweenRetries;
    }

    public int getMaxRetries() {
        return maxRetries;
    }

    public void setMaxRetries(int maxRetries) {
        this.maxRetries = maxRetries;
    }

    public int getSessionTimeoutMs() {
        return sessionTimeoutMs;
    }

    public void setSessionTimeoutMs(int sessionTimeoutMs) {
        this.sessionTimeoutMs = sessionTimeoutMs;
    }

    public int getConnectTimeoutMs() {
        return connectTimeoutMs;
    }

    public void setConnectTimeoutMs(int connectTimeoutMs) {
        this.connectTimeoutMs = connectTimeoutMs;
    }

    public String getNamespace() {
        return namespace;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }
    public void validate(){
        if(connectString==null ||connectString.trim().length()==0){
            throw new RuntimeException("ZookpeerConfig.connectString is empty");
        }
    }
}
